<?php
abstract class AuSource extends AuPrototype{
	public $_mapper = array();
	public $result;
	protected $_relation = array();

	public function sourceName(){
		return get_class($this);
	}
	
	public function setMapper($mapper){
		$this->_mapper = $mapper;
		return $this;
	}
	
	public function addMapper($mapper){
		$this->_mapper = array_unique(array_merge($this->_mapper,$mapper));
		return $this;
	}
	
	public function getMapper(){
		return $this->_mapper;
	}
	
	public function addRelation($relationClass){
		$this->_relation[get_class($relationClass)] = $relationClass;
		return $this;
	}
	
	public function getRelation(){
		return $this->_relation;
	}
	
	public function shelfMapper($shelf){
		return $shelf;
	}
	
	/*
	public function buildMapper($sourceAttrValue){
		$mapper = array();
		foreach ($this->getMapper() as  $sourceAttr => $prototypeAttr){
			if (array_key_exists($sourceAttr, $sourceAttrValue)) {
				$mapper[$prototypeAttr] = $sourceAttrValue[$sourceAttr];
			}
			
		}
		return $mapper;
	}
	*/
	
	public function setPrototypeAttrs($attributes){		
		$this->getPrototype()->attributes($this->buildMapperValue($attributes));
		return $this;
	}
	
	public function buildMapperValue($attributes){
		$attributesValue = array();
		foreach ($this->getMapper() as $prototypeAttr){
			if (array_key_exists($prototypeAttr, $attributes)) {
				$attributesValue[$prototypeAttr] = $attributes[$prototypeAttr];
			}
		}
		return $attributesValue;
	}
	
	/*
	public function attributes($attributes){
		foreach ($attributes as $key => $value){
			if (property_exists($this,$key)){
				$this->$key = $value;
			}
		}
		return $this;
	}
	*/
	abstract function find($shelf);
	abstract function findAll($shelf);
}